package com.xiangban.volunteer_platform.controller;

import com.xiangban.volunteer_platform.entity.Orders;
import com.xiangban.volunteer_platform.service.OrderService;
import com.xiangban.volunteer_platform.utils.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Mr. Ma
 * @Data 2021/1/22 15:26
 */

@RestController
@RequestMapping("/api/order")
@Api(tags = "订单控制器")
public class OrdersController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/saveOrder")
    @ApiOperation("添加订单信息")
    public JsonData saveOrder(@RequestBody Orders orders){
        orderService.saveOrder(orders);
       return JsonData.buildSuccess(orders.getId());
    }
    @PostMapping("/delOrder")
    @ApiOperation("删除订单信息")
    public JsonData delOrder(@RequestBody Orders orders){
        int i = orderService.delOrder(orders);
        if(i==-1){
            return JsonData.buildError("删除失败，无此订单");
        }
        return JsonData.buildSuccess();
    }

    @PostMapping("/updateOrder")
    @ApiOperation("修改订单信息")
    public JsonData updateOrder(@RequestBody Orders orders){
        int i = orderService.updateOrder(orders);
        if(i==-1){
            return JsonData.buildError("修改失败，无此订单");
        }
        return JsonData.buildSuccess();
    }

    @PostMapping("/getAllOrder")
    @ApiOperation("分页列表")
    public JsonData getAllOrder(@RequestParam(required = false) Integer pageNum,
                                @RequestParam(required = false) Integer pageSize,@RequestBody Orders orders){
        return JsonData.buildSuccess(orderService.getAllOrder(pageNum,pageSize, orders));
    }


}
